/**
 * admui-basic v2.1.0 (http://www.admui.com/)
 * Copyright 2015-2019 Admui Team
 * Licensed under the Admui License 1.1 (http://www.admui.com/about/license)
 */
(function(window, document, $) {
  'use strict';

  window.App.extend({
    run: function() {
      $('#dataTableExample').dataTable(
        $.concatCpt('dataTable', {
          footerCallback: function() {
            var api = this.api();
            var intVal = function(i) {
              var n = i;
              if (typeof n === 'string') {
                return n.replace(/[¥,]/g, '') * 1;
              }

              return typeof i === 'number' ? i : 0;
            };

            // 所有页
            var total = api
              .column(5)
              .data()
              .reduce(function(a, b) {
                return intVal(a) + intVal(b);
              }, 0);

            // 当前页
            var pageTotal = api
              .column(5, {page: 'current'})
              .data()
              .reduce(function(a, b) {
                return intVal(a) + intVal(b);
              }, 0);

            // 更新foot
            $(api.column(5).footer()).html('￥' + pageTotal + ' ( 共计：￥' + total + ')');
          }
        })
      );
    }
  });

  window.App.run();
})(window, document, jQuery);
